package com.health.fragment.jtys;

import com.health.NovaApplication;
import com.health.R;
import com.health.adapter.MainMenuGridAdapter_AdminJTYS;
import com.health.fragment.NovaFragment;
import com.health.activity.settings.DataDownLoadMainActivity;
import com.health.activity.settings.DataSynchronizationMainActivity;
import com.health.activity.settings.SystemSettingActivity;
import com.health.tools.GlobalConts;
import com.novabluetooth.views.BluetoothDeviceBindActivity2;

import android.app.ProgressDialog;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

/**
 * 医生设置页面
 * 
 * @author nova
 *
 */
public class JTYSSettings extends NovaFragment {

	private GridView gd_menu;
	private MainMenuGridAdapter_AdminJTYS menuAdapter;
	protected ProgressDialog progressDialog;
	private View jtysSettingView = null;

	@Override
	public View findViews(LayoutInflater inflater) {
		jtysSettingView = inflater.inflate(R.layout.jtys_settings, null);
		initViews(jtysSettingView);
		return jtysSettingView;
	}

	@Override
	public void setupView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addListener() {
		// 菜单选项
		gd_menu.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// 0"系统设置", 1"蓝牙设备绑定",2"数据上传", 3"综合统计"
				Intent intent = null;
				if (position == 0) {
					// 0 "系统设置",
					intent = new Intent(getActivity(), SystemSettingActivity.class);
				} else if (position == 1) {
					// 1 "蓝牙设备绑定",
					if (NovaApplication.idCardTool != null) {
						NovaApplication.idCardTool.removeListener();
						NovaApplication.idCardTool.setiNeedReadCount(1);
					}
//					if (NovaApplication.bloothTool != null) {
//						NovaApplication.bloothTool.scanLeDevice(false);
//					}
					intent = new Intent(getActivity(), BluetoothDeviceBindActivity2.class);
				}else if (position == 2) {
					//同步数据
					intent = new Intent(getActivity(), DataDownLoadMainActivity.class);
				} else if (position == 3) {
					// 同步机构人员
					intent = new Intent(getActivity(), DataSynchronizationMainActivity.class);
				} 
				
				if (intent != null ){
					startActivity(intent);
				}
			}
		});
	}

	@Override
	public void setData() {

	}
	
//	@Override
//	public void onActivityResult(int requestCode, int resultCode, Intent data) {
//		if (resultCode == 20) {
//			int page = Integer.parseInt(data.getStringExtra("page"));
//			MainActivity_Menu_JTYS.viewPager.setCurrentItem(page);
//		}
//		
//		super.onActivityResult(requestCode, resultCode, data);
//		
//	}

	/**
	 * 初始化布局
	 * 
	 * @author 王婷婷
	 * @date 2017年2月10日 下午3:17:44
	 */
	private void initViews(View v) {

		gd_menu = (GridView) v.findViewById(R.id.gd_menu);
		menuAdapter = new MainMenuGridAdapter_AdminJTYS(getActivity(), GlobalConts.MENU_SETTINGS);
		gd_menu.setAdapter(menuAdapter);

	}

}
